﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//
using ddcCajamarca.BusinessEntities.AgendaCultural;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;

namespace ddcCajamarca.Repository.Mapping
{
    public class DetalleEventoMap:EntityTypeConfiguration<DetalleEvento>
    {
        public DetalleEventoMap()
        {
            //primary key
            this.HasKey(t => new { t.EventId, OrganizacionId = t.OrganizacionId });

            //properties
            this.Property(t => t.EventId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            this.Property(t => t.OrganizacionId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Aporte)
                .IsOptional();
            this.Property(t => t.Otros)
                .IsOptional();
            this.Property(t => t.Tipo)
                .HasColumnType("varchar")
                .HasMaxLength(20)
                .IsRequired();

            //relationships
            this.HasRequired(t => t.Evento)
                .WithMany(t => t.DetalleEventoes)
                .HasForeignKey(d => d.EventId)
                .WillCascadeOnDelete(true);

            this.HasRequired(t => t.Organizacion)
                .WithMany()
                .HasForeignKey(d => d.OrganizacionId)
                .WillCascadeOnDelete(false);
            
        }
    }
}
